package com.jt.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;


//@Mapper //为接口创建了反射机制一个对象
//MP规则:
public interface UserMapper extends BaseMapper<User> {

    //查询全部用户信息 访问修饰符 返回值类型 方法名(参数...)
    List<User> findAll();

    @Insert("insert into demo_user(id,name,age,sex) value(null,#{name},#{age},#{sex})")
    void insertUser(User user);

    @Insert("update demo_user set name = #{newName} where name=#{oldName}")
    void updateByName(String oldName, String newName);

    @Delete("delete from demo_user where name = #{name}")
    void deleteByName(String name);

    @Select("select * from demo_user where id=#{id}")
    List<User>getById(Integer id);

    @Select("select * from demo_user where name=#{name} and sex=#{sex}")
    List<User>getByName(String name,String sex);

    @Select("select * from demo_user where age>#{age} and sex=#{sex}")
    List<User>getBy(Integer age,String sex);

    @Select("select * from demo_user where name like '%${name}'")
    List<User>getA(String name);

    @Select("select * from demo_user where id in(#{a},#{b},#{c},#{d})}")
    List<User>getB(Integer a,Integer b,Integer c,Integer d);

    @Select("select * from demo_user where name=#{name}")
    List<User>getC(String name);
}